package com.cn.crmsystem.service.customerService.impl;

import com.cn.crmsystem.mapper.customerMapper.ClueMapper;
import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.customerService.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ClueServiceImpl implements ClueService {
    @Autowired
    private ClueMapper clueMapper;
    @Override
    public ResultJson insertClue(Customer clue,Login login) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("clue",clue);
        map.put("login",login);
        if(clueMapper.insertClue(map)>0){
            return new ResultJson<>().getSuccess("添加成功");
        }else{
            return new ResultJson<>().getSuccess("添加失败");
        }
    }

    @Override
    public ResultJson deleteClue(Integer id) {
        if(clueMapper.deleteClue(id)>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }


    @Override
    public ResultJson addClueFollow(Login login, Follow_Up follow_up) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("login",login);
        map.put("follow",follow_up);
        if(clueMapper.addClueFollow(map)>0){
            return new ResultJson<>().getSuccess("添加成功");
        }else{
            return new ResultJson<>().getSuccess("添加失败");
        }
    }

    @Override
    public ResultJson updateClue(Customer clue) {
        if(clueMapper.updateClue(clue)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }

    @Override
    public ResultJson updateClueUser(Integer id) {
        if(clueMapper.updateClueUser(id)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }

    @Override
    public ResultJson<List> selectClue(Map map) {
        List list =clueMapper.selectClue(map);
        Long count=clueMapper.selectClueCount(map);
        if(list!=null && list.size()>0){
            return new ResultJson<>().getSuccess("查询成功",list,count);
        }else{
            return new ResultJson<>().getSuccess("查询失败");
        }
    }

    @Override
    public ResultJson updateClueCustomer(Integer id) {
        if(clueMapper.updateClueCustomer(id)>0){
            return new ResultJson<>().getSuccess("转化成功");
        }else{
            return new ResultJson<>().getSuccess("转化失败");
        }
    }

    @Override
    public ResultJson deleteAllClue(Integer[] ids) {
        int result=0;
        for(int i=0;i<ids.length;i++){
            result=clueMapper.deleteClue(ids[i]);
        }
        if(result>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }
}
